package com.origin.learn.dbpool;

import java.sql.Connection;

/**
 * @Description:
 * @Date: 2020/2/29
 * @Time: 14:55
 * @Created by:   dingtao
 * @Modified by:
 * @Modified at:
 */
public class Test {

    public static void main(String[] args) {
        int initSize = 10;
        int coreSize = 20;
        int maxSize = 30;
        long checkIntervalTime = 1000L;

        String param1 = "localhost:3306";
        String param2 = "username";
        String param3 = "password";

        ConnectionPool pool = new StupidUselessConnectionPool(initSize, coreSize, maxSize, checkIntervalTime,param1, param2, param3);

        new Thread((AbstractConnectionPool)pool).start();
        for (int i = 0; i < 20; i++) {
            Connection connection = pool.getConnection();
            if (Math.random()<0.5){
                pool.putBackConnection(connection);
            }
        }
        try{
            Thread.sleep(10000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        System.out.println("try to kill pool");
        pool.kill();
    }
}
